import yaml

from test_pom.test3_Litemall接口自动化测试项目实战.utils.log_utils import logger


class Utils:
    @classmethod
    def get_yaml_data(cls, file_path):
        with open(file_path, 'r', encoding='utf-8') as f:
            res = yaml.safe_load(f)
            logger.info("yaml.safe_load()读取时，默认只支持读取「单个文档」")
            return res

    @classmethod
    def get_yaml_data_any_data(cls, file_path):
        with open(file_path, 'r', encoding='utf-8') as f:
            all_data = list(yaml.safe_load_all(f))
            logger.info("YAML 文件中包含多个文档（用---分隔）")
        return all_data


if __name__ == '__main__':
    utils = Utils()
    data = utils.get_yaml_data_any_data(
        r'D:\python_class\Interface_automation_test\test_pom\test3_Litemall接口自动化测试项目实战\data\add_goods.yaml')
    # data1 = utils.get_yaml_data(
    #     r"D:\python_class\Interface_automation_test\test_pom\test1_pets_stor\data\update_yaml.yaml")
    print(data[0])
